#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <thread>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lcdNumber->display("5");
    std::thread t1([this](){
        int value = ui->lcdNumber->intValue();
        while(value>0)
        {
            std::this_thread::sleep_for(std::chrono::seconds(1));
            value--;
            ui->lcdNumber->display(value);
        }
    });

//    int value = ui->lcdNumber->intValue();
//    while(value>0)
//    {
//        std::this_thread::sleep_for(std::chrono::seconds(1));
//        value--;
//        ui->lcdNumber->display(value);
//    }

//    timer = new QTimer(this);
//    connect(timer,&QTimer::timeout,this,&Widget::handle);

//    timer->start(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    int value = ui->lcdNumber->intValue();
    if(value <= 0)
    {
        timer->stop();
        return;
    }
    ui->lcdNumber->display(value - 1);
}

